﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Client;

namespace PersApp
{
    public partial class LoginForm : Form
    {
        // members
        private UserRights user = UserRights.None; // Права пользователя
        private RepositoryManager repMan; // объект для доступа к серверу
        private string ErrorText = "Неверный логин или пароль!";

        public UserRights User
        {
            get { return user; }
        }

        public RepositoryManager RepMan
        {
            get { return repMan; }
        }

        public LoginForm()
        {
            InitializeComponent();
        }

        private void buttonCancel_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void buttonEnter_Click(object sender, EventArgs e)
        {
            string login = this.textBoxLogin.Text;
            string password = this.textBoxPassword.Text;

            repMan = RepositoryManager.GetRepositoryManager(login, password);

            if (repMan.TimeTableRepository.LogIn())
            {
                user = UserRights.Employer;
                Close();
            }
            else
            {
                user = UserRights.None;
                textBoxPassword.Text = string.Empty;
                labelError.Text = ErrorText;
            }
        }


    }
}
